/*
 * @Author: lmk
 * @Date: 2019-07-10 15:13:53
 * @LastEditTime: 2022-06-14 15:05:16
 * @LastEditors: lmk
 * @Description:二次封装axios
 */
import axios from 'axios'
// create an axios instance
const service = axios.create({
  baseURL: 'http://39.101.180.248:9786/api/yuanjiu.website',
  // baseURL: 'http://hjqqa.nat300.top/api/yuanjiu.website',
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 10000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// response interceptor
service.interceptors.response.use(
  /**
   * If you want to get http information such as headers or status
   * Please return  response => response
  */

  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    const {data} = response
    if(data.code!==200){
      return Promise.reject(new Error(data.message || 'Error'))
    }
    return data.result;
  },
  error => {
    console.log('err' + error) // for debug
    return Promise.reject(error)
  }
)

export default service
